<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
 <meta name="Page-topic" content="ST-Open Tutorial: Loading Fields" />
 <meta name="Description" content="ST-Open Tutorial: Loading Fields" />
 <meta name="Keywords" content="ST-Open Software, Open Source, ST-Open, Software, library, libraries, free software, assembler, C" />
    <meta name="date" content="2009-05-08T00:00:00+00:00" />
 <meta name="robots" content="index,follow" />
 <meta name="revisit-after" content="14 days" />
 <meta name="generator" content="Bernhard Schornak, handwritten" />
 <style type="text/css"><!--@import "../../st.css";--></style>
 <link rel="SHORTCUT ICON" href="../../../../pics/favicon.ico" />
 <title>Loading Fields</title>
</head>
<body id="top">
<div class="pagehd">
<div id="menu">
<ul>
 <li><a href="../../../indexe.htm">Software</a></li>
 <li><a href="index.htm">Tutorials</a></li>
 <li><a href="../index.htm">Documentation</a></li>
 <li><a href="../alp.htm">alphabetical</a></li>
 <li><a href="../fct.htm">by Function</a></li>
</ul>
</div>
<div class="update">[2009-05-08]</div><div class="headpc"><img src="../../pics/ste.png" alt="SourceDoc Logo" width="75" height="75" border="0" /></div>
</div>
<div class="crlf1"></div>
&#160;&#160;&#160;<a href="index.htm"><img src="../../../../pics/nav_up.png" alt="up" width="20" height="20" border="0" title="up" /></a>
&#160;&#160;&#160;<a href="0402.htm"><img src="../../../../pics/nav_bk.png" alt="previous" width="20" height="20" border="0" title="previous" /></a>
&#160;&#160;&#160;<a href="0404.htm"><img src="../../../../pics/nav_fw.png" alt="next" width="20" height="20" border="0" title="next" /></a>
<div class="text100">
<h1>Loading Fields</h1>
The procedure with the LD structure is always the same, so I skip the enumeration of these
 steps. The first parameter for the field request is the field number. This might be any
 number in the range of 0x00000001 through 0xFFFFFFBF. 0x00000000 is no field, all numbers
 above 0xFFFFFFBF are reserved for the system. Let's use number 0x00000001:
<div class="box100q"><pre>
DD Test(VOID)
{
 LD ld;
 DD mh, rc;
 Mcl(&amp;ld, 40);
 ld.FldNr = 0x00000001;
</pre></div>
The second parameter are the control flags:
<div class="box100q"><pre>
 ld.LdCtl = LDR_READ | LDR_WRITE;
</pre></div>
We just grant read and write permission, that's all we need. If you want to switch off
 dynamic memory management, just or <b>| LDR_STATIC</b> with the other two flags. These
 are all parameters we need to call the Loader:
<div class="box100q"><pre>
 rc = LDreq(&amp;ld);
 if(rc)
 {
  return(rc);
 }
 mh = ld.MMoff;
</pre></div>
The field is ready to use. Because fields are accessed via their MemHandle, you should
 store <b>ld.MMoff</b> in a variable. I use <b>mh</b> in this example. If the field
 should be accessible from other functions, it might be a good idea to store the MemHandle
 in a global variable like MY_FIELD. The offset of MY_FIELD to BNR must be defined in a
 header file like: #define MY_FIELD ((BNR) + 0x244C).
<div class="box100q"><pre>
 PUT(MY_FIELD, mh);
</pre></div>
You can access the field with the database engine now:
<div class="box100q"><pre>
 rc = FDacc(mh, 0, 0, FDA_READ, 0, 0);
</pre></div>
After the work is done, the resource should be freed:
<div class="box100q"><pre>
 LDfre(mh);
</pre></div>
The entire code in one piece:
<div class="box100q"><pre>
DD Test(VOID)
{
 LD ld;
 DD rc;
 Mcl(&amp;ld, 40);
 ld.FldNr = 0x00000001;
 ld.LdCtl = LDR_READ | LDR_WRITE;
 rc = LDreq(&amp;ld);
 if(rc)
 {
  return(rc);
 }
 mh = ld.MMoff;
 PUT(MY_FIELD, mh);
 /*
   FUNCTION CODE
 */
 rc = FDacc(mh, 0, 0, FDA_READ, 0, 0);
 /*
   MORE CODE
 */
 rc = Helper();
 /*
   EVEN MORE CODE
 */
 LDfre(mh);
 PUT(MY_FIELD, 0);
 return(rc);
}

/**************************************
 HELPER FUNCTION
 using the MemHandle stored in MY_FIELD
**************************************/

DD Helper(VOID)
{
 DD mh = GET(MY_FIELD),
    rc;
 rc = FDacc(mh, 0, 0, FDA_READ, 0, 0);
 return(rc);
} 
</pre></div>
<div class="crlf1"></div>
The next page explains how to load a file with the Loader.
</div>
<div class="crlf2"></div>
&#160;&#160;&#160;<a href="index.htm"><img src="../../../../pics/nav_up.png" alt="up" width="20" height="20" border="0" title="up" /></a>
&#160;&#160;&#160;<a href="0402.htm"><img src="../../../../pics/nav_bk.png" alt="previous" width="20" height="20" border="0" title="previous" /></a>
&#160;&#160;&#160;<a href="0404.htm"><img src="../../../../pics/nav_fw.png" alt="next" width="20" height="20" border="0" title="next" /></a>
<div class="crlf1"></div>
</body>
</html>
